package com.heima.service;

import com.heima.domain.TextMessage;
import com.heima.utils.MessageUtil;
import com.heima.utils.WeixinMessageUtil;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class WeChatService {
    //处理微信推送过来的消息
    public String handerMessage(Map<String, String> map) {
        String reciveMessage = "";
        if (map.get("MsgType").equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
            TextMessage textMessage = new TextMessage();
            textMessage.setCreateTime(map.get("CreateTime"));
            textMessage.setToUserName(map.get("FromUserName")); //用户
            textMessage.setFromUserName(map.get("ToUserName")); //公众号id
            textMessage.setContent("你好");
            textMessage.setMsgType(map.get("MsgType"));
             reciveMessage = MessageUtil.textMessageToXml(textMessage);
            System.out.println("回复的消息"+reciveMessage);
        }

        return reciveMessage;
    }
}
